
class TestHabraTopic(TestCase):
    def test_topic(self):
        t = HabraTopic(231957)
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(t.author())
        self.assertEqual(t.author(), '@yaklamm')
        pp.pprint(t.title())
        self.assertEqual(t.title(), 'Memory management в ядре Linux. Семинар в Яндексе')
        pp.pprint(t.post['comments_count'])
        pp.pprint(t.post['rating'])

    def test_topic2(self):
        t = HabraTopic(208802)
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(t.author())
        self.assertEqual(t.author(), '@icoz')
        self.assertEqual(t.title(), 'Экспорт Избранного на Хабре в PDF')
        pp.pprint(t.title())
        pp.pprint(t.post['comments_count'])
        pp.pprint(t.post['rating'])
        self.assertEqual(t.comments()[0]['author'], 'keccak')
        self.assertEqual(t.comments()[1]['author'], 'icoz')

    def test_topic3(self):
        t = HabraTopic(28108)
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(t.author())
        self.assertEqual(t.author(), '@cachealot')
        self.assertEqual(t.title(), 'эффективное использование vim: «from the very begining»')
        pp.pprint(t.title())
        pp.pprint(t.post['comments_count'])
        pp.pprint(t.post['rating'])
        self.assertEqual(t.comments()[0]['author'], 'cachealot')
        from lxml import html
        txt = html.fromstring(t.comments()[0]['text']).text_content().replace("'",'').strip()
        self.assertEqual(txt, 'не поверите, 3,5 часа убил на пост )')
        self.assertEqual(t.comments()[0]['c_id'], 734629)
        self.assertEqual(t.comments()[0]['p_id'], 0)
        self.assertEqual(t.comments()[1]['author'], 'ShPashok')
        txt = html.fromstring(t.comments()[1]['text']).text_content().replace("'",'').strip()
        self.assertEqual(txt, 'а 2 секунды на хабракат пожалели :)')
        self.assertEqual(t.comments()[1]['c_id'], 734630)
        self.assertEqual(t.comments()[1]['p_id'], 734629)


